home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_6547.txt < prev    next >
Text File  |  1991-02-27  |  2KB  |  40 lines

  1. -- card: 6547 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 6
  9. ----- text -----
  10. 9.3  Class Ideas
  11.  
  12. -- part contents for background part 4
  13. ----- text -----
  14. C++ provides "constructor" and "destructor" member functions which are automatic- ally invoked upon allocation and deallocation of objects.  Typically the constructor initializes the values of the instance variables and/or performs dynamic memory allocation, while the destructor deallocates any dynamically-allocated memory.
  15.  
  16. This section extends the Generic_Class files given in the example in Chapter 4 and suggests new global functions new_init() and destroy_delete() to supplant the TC new() and delete() functions defined in the oops library.  These alternative functions automatically invoke an object's init() and destroy() member functions to simulate C++ constructors and destructors.  They also work for both direct and indirect objects*.
  17.  
  18. Unlike the C++ constructor/destructor approach, however, this technique has the potential to ensure that any dynamic memory allocation in the init() method succeeds before an object pointer is assigned.  That is, new_init() returns either:  (1) NULL if the object cannot be allocated, (2) NULL if the object is allocated but its init() method fails (in which case all allocated memory is released), or (3) a pointer to a successfully-initialized object.  IMPORTANT: the code on the following pages must be modified to work in C++, as discussed in the comments.
  19.  
  20.  
  21.  
  22. -- part contents for background part 29
  23. ----- text -----
  24. 38494
  25.  
  26. -- part contents for background part 27
  27. ----- text -----
  28. Direct & indirect objects
  29.  
  30. -- part contents for background part 20
  31. ----- text -----
  32. Direct & indirect objects - p123
  33.  
  34. -- part contents for background part 7
  35. ----- text -----
  36. 209
  37.  
  38. -- part contents for background part 17
  39. ----- text -----
  40. p3